Below are some tips and tricks that I have picked up along my R journey, that may (or may not!) be useful for those working with sport science data, or any data, in R. I hope you find the tips useful!
If you are interested in working with some real life netball data, you can see a slidedeck that I put together of how to import, tidy and analyse the data here.
Sometimes, someone will share some data with us via Dropbox. Often these files can be really big and it is annoying to download a local copy of these files on your machine. If you have been sent a link to view these files, the following may be useful so you can load them directly into R, without having to save the file locally on your machine first.
# Install the {vroom} package
install.packages(vroom)
# Load the package from your library
library(vroom)
# Load your data directly into R!
data <- vroom("https://www.dropbox.com/s/sometexthere/NameOfFile.csv?dl=1")
Use R to quickly import AMS your data and not even open a web browser! To do this, please follow the steps below. Note – I am using Smartabase as an example here because it is familiar to me.
# Load required packages
library(rvest)
library(plyr)
library(dplyr)
library(qdap)
# Connect to a report that you have generated via Smartabase
WellnessDataURL <- html_session("https://username:password@my2.smartabase.com/yourteamsname/live?report=WellnessData&updategroup=true")
# Read in data
WellnessData <- read_html(WellnessDataURL)
# Identify the table
WellnessDataTable <- html_nodes(WellnessData, "table")
# Collect only table data
WellnessDataTable1 <- html_table(WellnessDataTable[1], fill = TRUE)
# Make data.frame
HistoricalWellnessData <- as.data.frame(WellnessDataTable1)
# Clean Environment
rm(list = grep("^HistoricalWellnessData", ls(), value = TRUE, invert = TRUE))
Now your AMS data is in a neat data.frame and ready for any further statistical analysis or visualisation using R, without needing to open a web browser!